package com.bort.system.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bort.system.info.CostInfo;
import com.bort.system.info.OrderInfo;
import com.bort.system.service.TOrderService;
import com.bort.system.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin/order")
public class AdminOrderController {

    @Resource
    TOrderService orderService;

    @RequestMapping("/list")
    public Result<Page<OrderInfo>> index(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "rowSize", defaultValue = "12") Integer rowSize,
            @RequestParam(value = "orderNo",required = false) String orderNo,
            @RequestParam(value = "businessType",required = false)Integer businessType,
            @RequestParam(value = "timeBegin",required = false) String timeBegin,
            @RequestParam(value = "timeEnd",required = false) String timeEnd
    ) {
        Page<OrderInfo> pager = new Page<>();
        pager.setSize(rowSize);
        pager.setCurrent(page);
        Map<String,Object> map = new HashMap<>();
        map.put("orderNo",orderNo);
        map.put("businessType",businessType);
        map.put("timeBegin",timeBegin);
        map.put("timeEnd",timeEnd);
        return orderService.getOrderList(pager,map);
    }

   @RequestMapping("/statistic")
   public Result statistic(
           @RequestParam(value = "orderNo",required = false) String orderNo,
           @RequestParam(value = "businessType",required = false)Integer businessType,
           @RequestParam(value = "timeBegin",required = false) String timeBegin,
           @RequestParam(value = "timeEnd",required = false) String timeEnd
   ){
       Map<String,Object> map = new HashMap<>();
       map.put("orderNo",orderNo);
       map.put("businessType",businessType);
       map.put("timeBegin",timeBegin);
       map.put("timeEnd",timeEnd);
       return orderService.dataStatistic(map);
   }

   @RequestMapping(value = "/cost",method = RequestMethod.POST)
   public Result cost(@RequestBody CostInfo costInfo){
        return orderService.addCost(costInfo);
   }
}
